package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 新增员工信息
     * @param employee 员工信息
     * @return 新增结果
     */
    @Insert("insert into employee (name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser});")
    @AutoFill(value = OperationType.INSERT)
    int insEmployee(Employee employee);

    /**
     * 分页查询 员工信息
     * @param employeePageQueryDTO 查询参数
     * @return 查询结果
     */
    List<Employee> getEmployeePageList(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 禁用员工
     * @param status 禁用状态
     * @param id 员工ID
     * @return 返回操作结果
     */
    @AutoFill(value = OperationType.UPDATE)
    int disableEmployeesStatus(@Param("status") String status,@Param("id") Long id);

    /**
     * 根据id查询员工信息
     * @param id 员工id
     * @return 员工信息
     */
    @Select("select * from employee where id = #{id};")
    Employee getEmployeeById(@Param("id") Long id);

    /**
     * 编辑修改员工信息
     * @param employee 员工信息
     * @return 操作结果
     */
    @Update("update employee set username = #{username}, name = #{name}, phone = #{phone}, sex = #{sex}, " +
            "id_number = #{idNumber}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id};")
    @AutoFill(value = OperationType.UPDATE)
    int updateEmployee(Employee employee);
}
